package com.chatplus.application.controller.admin.file;
import com.chatplus.application.domain.entity.file.SysOssConfigEntity;
import com.chatplus.application.service.file.SysOssConfigService;
import com.chatplus.application.web.basecontroller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 对象存储配置
 */
@Validated
@RestController
@RequestMapping("/system/oss/config")
public class SysOssConfigController extends BaseController {

    private final SysOssConfigService iSysOssConfigService;

    public SysOssConfigController(SysOssConfigService iSysOssConfigService) {
        this.iSysOssConfigService = iSysOssConfigService;
    }
    /**
     * 获取对象存储配置详细信息
     *
     * @param ossConfigId OSS配置ID
     */
    @GetMapping("/{ossConfigId}")
    public SysOssConfigEntity getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable Long ossConfigId) {
        return iSysOssConfigService.getById(ossConfigId);
    }

    /**
     * 新增对象存储配置
     */
    @PostMapping("/add")
    public void add(@RequestBody SysOssConfigEntity bo) {
        iSysOssConfigService.save(bo);
    }

    /**
     * 修改对象存储配置
     */
    @PutMapping("/edit")
    public void edit(@RequestBody SysOssConfigEntity bo) {
        iSysOssConfigService.updateById(bo);
    }

    /**
     * 删除对象存储配置
     *
     * @param ossConfigIds OSS配置ID串
     */
    @DeleteMapping("/{ossConfigIds}")
    public void remove(@NotEmpty(message = "主键不能为空")
                       @PathVariable Long[] ossConfigIds) {
        iSysOssConfigService.removeBatchByIds(Arrays.asList(ossConfigIds));
    }
}
